package edu.study.user.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import edu.study.api.common.dto.BaseRespDto;
import edu.study.api.common.dto.RespDto;
import edu.study.common.util.cache.Lock;
import edu.study.common.util.cache.LockExecuteCallback;
import edu.study.user.api.RoleAuthApi;
import edu.study.user.api.dto.RoleAuthDto;
import edu.study.user.api.req.roleauth.QueryRoleAuthReq;
import edu.study.user.api.req.roleauth.RoleAuthReq;
import edu.study.user.service.RoleAuthService;

@RestController
public class RoleAuthApiImpl implements RoleAuthApi {

	@Autowired
    private Lock lock;

    @Autowired
    private RoleAuthService roleAuthService;

	@Override
	public BaseRespDto addRoleAuth(@RequestBody RoleAuthReq req) {
		BaseRespDto resp = lock.lockAndExecute(req.getRoleNo(), req.get_requestId(), new LockExecuteCallback() {
            @Override
            public BaseRespDto doBusiness() {
                BaseRespDto resp1 = roleAuthService.addRoleAuth(req);
                return resp1;
            }
        });
		return resp;
	}

	@Override
	public BaseRespDto deleteRoleAuth(@RequestBody RoleAuthReq req) {
		BaseRespDto resp = lock.lockAndExecute(req.getRoleNo(), req.get_requestId(), new LockExecuteCallback() {
            @Override
            public BaseRespDto doBusiness() {
                BaseRespDto resp1 = roleAuthService.deleteRoleAuth(req);
                return resp1;
            }
        });
		return resp;
	}

	@Override
	public BaseRespDto modifyRoleAuth(@RequestBody RoleAuthReq req) {
		BaseRespDto resp = lock.lockAndExecute(req.getRoleNo(), req.get_requestId(), new LockExecuteCallback() {
            @Override
            public BaseRespDto doBusiness() {
                BaseRespDto resp1 = roleAuthService.modifyRoleAuth(req);
                return resp1;
            }
        });
		return resp;
	}

	@Override
	public RespDto<List<RoleAuthDto>> queryRoleAuthList(@RequestBody QueryRoleAuthReq req) {
		RespDto<List<RoleAuthDto>> resp = roleAuthService.queryRoleAuthList(req);
		return resp;
	}
}
